home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 April: Penguin on DISC / ADC Developer CD (1993-04) (''Penguin On DISC'')_iso / Dev.CD Apr 93.iso / Utilities / MPW Interfaces 7.1 Beta / PInterfaces / Sound.p < prev    next >
Encoding:
Text File  |  1992-08-28  |  15.1 KB  |  460 lines  |  [TEXT/MPS ]

  1. {
  2. Created: Tuesday, March 5, 1991 at 5:12 PM
  3.     Sound.p
  4.     Pascal Interface to the Macintosh Libraries
  5.  
  6.         Copyright Apple Computer, Inc.    1986-1991
  7.         All rights reserved
  8.  
  9. *** Warning: This is an alpha version of the Interfaces for Cube-E. 
  10. ***          Things may change.  Caveat Programmer.
  11.  
  12.  
  13. }
  14.  
  15.  
  16. {$IFC UNDEFINED UsingIncludes}
  17. {$SETC UsingIncludes := 0}
  18. {$ENDC}
  19.  
  20. {$IFC NOT UsingIncludes}
  21.     UNIT Sound;
  22.     INTERFACE
  23. {$ENDC}
  24.  
  25. {$IFC UNDEFINED UsingSound}
  26. {$SETC UsingSound := 1}
  27.  
  28. {$I+}
  29. {$SETC SoundIncludes := UsingIncludes}
  30. {$SETC UsingIncludes := 1}
  31. {$IFC UNDEFINED UsingTypes}
  32. {$I $$Shell(PInterfaces)Types.p}
  33. {$ENDC}
  34. {$IFC UNDEFINED UsingFiles}
  35. {$I $$Shell(PInterfaces)Files.p}
  36. {$ENDC}
  37. {$SETC UsingIncludes := SoundIncludes}
  38.  
  39. CONST
  40. swMode = -1;                                    { Sound Driver modes }
  41. ftMode = 1;
  42. ffMode = 0;
  43.  
  44. synthCodeRsrc = 'snth';                         { Resource types used by Sound Manager }
  45. soundListRsrc = 'snd ';
  46.  
  47. twelfthRootTwo = 1.05946309434;
  48. rate22khz = $56EE8BA3;                          { 22254.54545 in fixed-point }
  49. rate11khz = $2B7745D1;                          { 11127.27273 in fixed-point }
  50.  
  51. { synthesizer numbers for SndNewChannel }
  52. squareWaveSynth = 1;                            {square wave synthesizer}
  53. waveTableSynth = 3;                             {wave table synthesizer}
  54. sampledSynth = 5;                               {sampled sound synthesizer}
  55.  
  56. { old Sound Manager MACE synthesizer numbers }
  57. MACE3snthID = 11;
  58. MACE6snthID = 13;
  59.  
  60. { command numbers for SndDoCommand and SndDoImmediate }
  61. nullCmd = 0;
  62. initCmd = 1;
  63. freeCmd = 2;
  64. quietCmd = 3;
  65. flushCmd = 4;
  66. reInitCmd = 5;
  67.  
  68. waitCmd = 10;
  69. pauseCmd = 11;
  70. resumeCmd = 12;
  71. callBackCmd = 13;
  72. syncCmd = 14;
  73. emptyCmd = 15;
  74.  
  75. tickleCmd = 20;
  76. requestNextCmd = 21;
  77. howOftenCmd = 22;
  78. wakeUpCmd = 23;
  79. availableCmd = 24;
  80. versionCmd = 25;
  81. totalLoadCmd = 26;
  82. loadCmd = 27;
  83.  
  84. scaleCmd = 30;
  85. tempoCmd = 31;
  86.  
  87. freqDurationCmd = 40;
  88. restCmd = 41;
  89. freqCmd = 42;
  90. ampCmd = 43;
  91. timbreCmd = 44;
  92. getAmpCmd = 45;
  93.  
  94. waveTableCmd = 60;
  95. phaseCmd = 61;
  96.  
  97. soundCmd = 80;
  98. bufferCmd = 81;
  99. rateCmd = 82;
  100. continueCmd = 83;
  101. doubleBufferCmd = 84;
  102. getRateCmd = 85;
  103.  
  104. sizeCmd = 90;
  105. convertCmd = 91;
  106.  
  107. stdQLength = 128;
  108. dataOffsetFlag = $8000;
  109.  
  110. waveInitChannelMask = $07;
  111. waveInitChannel0 = $04;
  112. waveInitChannel1 = $05;
  113. waveInitChannel2 = $06;
  114. waveInitChannel3 = $07;
  115.  
  116. { channel initialization parameters }
  117. initPanMask = $0003;                            { mask for right/left pan values }
  118. initSRateMask = $0030;                          { mask for sample rate values }
  119. initStereoMask = $00C0;                         { mask for mono/stereo values }
  120. initCompMask = $FF00;                           { mask for compression IDs }
  121.  
  122. initChanLeft = $0002;                           { left stereo channel }
  123. initChanRight = $0003;                          { right stereo channel }
  124. initNoInterp = $0004;                           { no linear interpolation }
  125. initNoDrop = $0008;                             { no drop-sample conversion }
  126. initMono = $0080;                               { monophonic channel }
  127. initStereo = $00C0;                             { stereo channel }
  128. initMACE3 = $0300;                              { MACE 3:1 }
  129. initMACE6 = $0400;                              { MACE 6:1 }
  130.  
  131. initChan0 = $0004;                              { channel 0 - wave table only }
  132. initChan1 = $0005;                              { channel 1 - wave table only }
  133. initChan2 = $0006;                              { channel 2 - wave table only }
  134. initChan3 = $0007;                              { channel 3 - wave table only }
  135.  
  136. stdSH = $00;                                    { Standard sound header encode value }
  137. extSH = $FF;                                    { Extended sound header encode value }
  138. cmpSH = $FE;                                    { Compressed sound header encode value }
  139.  
  140. notCompressed = 0;                              { compression ID's }
  141. twoToOne = 1;
  142. eightToThree = 2;
  143. threeToOne = 3;
  144. sixToOne = 4;
  145.  
  146. outsideCmpSH = 0;                               { MACE constants }
  147. insideCmpSH = 1;
  148. aceSuccess = 0;
  149. aceMemFull = 1;
  150. aceNilBlock = 2;
  151. aceBadComp = 3;
  152. aceBadEncode = 4;
  153. aceBadDest = 5;
  154. aceBadCmd = 6;
  155. sixToOnePacketSize = 8;
  156. threeToOnePacketSize = 16;
  157. stateBlockSize = 64;
  158. leftOverBlockSize = 32;
  159.  
  160. firstSoundFormat = $0001;                       { general sound format }
  161. secondSoundFormat = $0002;                      { special sampled sound format (HyperCard) }
  162.  
  163. dbBufferReady = $00000001;                      { double buffer is filled }
  164. dbLastBuffer = $00000004;                       { last double buffer to play }
  165.  
  166. sysBeepDisable = $0000;                         { SysBeep() enable flags }
  167. sysBeepEnable = $0001;
  168.  
  169. unitTypeNoSelection = $FFFF;                    { unitTypes for AudioSelection.unitType }
  170. unitTypeSeconds = $0000;
  171.  
  172. TYPE
  173. {            Structures for Sound Driver            }
  174.  
  175.  
  176. FreeWave = PACKED ARRAY [0..30000] OF Byte;
  177.  
  178. FFSynthPtr = ^FFSynthRec;
  179. FFSynthRec = RECORD
  180.     mode: INTEGER;
  181.     count: Fixed;
  182.     waveBytes: FreeWave;
  183.     END;
  184.  
  185. Tone = RECORD
  186.     count: INTEGER;
  187.     amplitude: INTEGER;
  188.     duration: INTEGER;
  189.     END;
  190.  
  191.  
  192. Tones = ARRAY [0..5000] OF Tone;
  193.  
  194. SWSynthPtr = ^SWSynthRec;
  195. SWSynthRec = RECORD
  196.     mode: INTEGER;
  197.     triplets: Tones;
  198.     END;
  199.  
  200.  
  201. Wave = PACKED ARRAY [0..255] OF Byte;
  202. WavePtr = ^Wave;
  203.  
  204. FTSndRecPtr = ^FTSoundRec;
  205. FTSoundRec = RECORD
  206.     duration: INTEGER;
  207.     sound1Rate: Fixed;
  208.     sound1Phase: LONGINT;
  209.     sound2Rate: Fixed;
  210.     sound2Phase: LONGINT;
  211.     sound3Rate: Fixed;
  212.     sound3Phase: LONGINT;
  213.     sound4Rate: Fixed;
  214.     sound4Phase: LONGINT;
  215.     sound1Wave: WavePtr;
  216.     sound2Wave: WavePtr;
  217.     sound3Wave: WavePtr;
  218.     sound4Wave: WavePtr;
  219.     END;
  220.  
  221. FTSynthPtr = ^FTSynthRec;
  222. FTSynthRec = RECORD
  223.     mode: INTEGER;
  224.     sndRec: FTSndRecPtr;
  225.     END;
  226.  
  227. {            Structures for Sound Manager            }
  228.  
  229. SndCommand = PACKED RECORD
  230.     cmd: INTEGER;
  231.     param1: INTEGER;
  232.     param2: LONGINT;
  233.     END;
  234.  
  235.  
  236. Time = LONGINT;                                 { in half milliseconds }
  237.  
  238.  
  239.  
  240. SndChannelPtr = ^SndChannel;
  241. SndChannel = PACKED RECORD
  242.     nextChan: SndChannelPtr;
  243.     firstMod: Ptr;                              { reserved for the Sound Manager }
  244.     callBack: ProcPtr;
  245.     userInfo: LONGINT;
  246.     wait: Time;                                 { The following is for internal Sound Manager use only.}
  247.     cmdInProgress: SndCommand;
  248.     flags: INTEGER;
  249.     qLength: INTEGER;
  250.     qHead: INTEGER;                             { next spot to read or -1 if empty }
  251.     qTail: INTEGER;                             { next spot to write = qHead if full }
  252.     queue: ARRAY [0..stdQLength - 1] OF SndCommand;
  253.     END;
  254.  
  255. { MACE structures }
  256. StateBlockPtr = ^StateBlock;
  257. StateBlock = RECORD
  258.     stateVar: ARRAY [0..stateBlockSize - 1] OF INTEGER;
  259.     END;
  260.  
  261. LeftOverBlockPtr = ^LeftOverBlock;
  262. LeftOverBlock = RECORD
  263.     count: LONGINT;
  264.     sampleArea: PACKED ARRAY [0..leftOverBlockSize - 1] OF Byte;
  265.     END;
  266.  
  267. ModRef = RECORD
  268.     modNumber: INTEGER;
  269.     modInit: LONGINT;
  270.     END;
  271.  
  272. SndListPtr = ^SndListResource;
  273. SndListResource = RECORD
  274.     format: INTEGER;
  275.     numModifiers: INTEGER;
  276.     modifierPart: ARRAY [0..0] OF ModRef;       {This is a variable length array}
  277.     numCommands: INTEGER;
  278.     commandPart: ARRAY [0..0] OF SndCommand;    {This is a variable length array}
  279.     dataPart: PACKED ARRAY [0..0] OF Byte;      {This is a variable length array}
  280.     END;
  281.  
  282. SoundHeaderPtr = ^SoundHeader;
  283. SoundHeader = PACKED RECORD
  284.     samplePtr: Ptr;                             { if NIL then samples are in sampleArea }
  285.     length: LONGINT;                            { length of sound in bytes }
  286.     sampleRate: Fixed;                          { sample rate for this sound }
  287.     loopStart: LONGINT;                         { start of looping portion }
  288.     loopEnd: LONGINT;                           { end of looping portion }
  289.     encode: Byte;                               { header encoding }
  290.     baseFrequency: Byte;                        { baseFrequency value }
  291.     sampleArea: PACKED ARRAY [0..0] OF Byte;
  292.     END;
  293.  
  294. CmpSoundHeaderPtr = ^CmpSoundHeader;
  295. CmpSoundHeader = PACKED RECORD
  296.     samplePtr: Ptr;                             { if nil then samples are in sample area }
  297.     numChannels: LONGINT;                       { number of channels i.e. mono = 1 }
  298.     sampleRate: Fixed;                          { sample rate in Apples Fixed point representation }
  299.     loopStart: LONGINT;                         { loopStart of sound before compression }
  300.     loopEnd: LONGINT;                           { loopEnd of sound before compression }
  301.     encode: Byte;                               { data structure used , stdSH, extSH, or cmpSH }
  302.     baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  303.     numFrames: LONGINT;                         { length in frames ( packetFrames or sampleFrames ) }
  304.     AIFFSampleRate: Extended80;                   { IEEE sample rate }
  305.     markerChunk: Ptr;                           { sync track }
  306.     futureUse1: Ptr;                            { reserved by Apple }
  307.     futureUse2: Ptr;                            { reserved by Apple }
  308.     stateVars: StateBlockPtr;                   { pointer to State Block }
  309.     leftOverSamples: LeftOverBlockPtr;          { used to save truncated samples between compression calls }
  310.     compressionID: INTEGER;                     { 0 means no compression, non zero means compressionID }
  311.     packetSize: INTEGER;                        { number of bits in compressed sample packet }
  312.     snthID: INTEGER;                            { resource ID of Sound Manager snth that contains NRT C/E }
  313.     sampleSize: INTEGER;                        { number of bits in non-compressed sample }
  314.     sampleArea: PACKED ARRAY [0..0] OF Byte;    { space for when samples follow directly }
  315.     END;
  316.  
  317. ExtSoundHeaderPtr = ^ExtSoundHeader;
  318. ExtSoundHeader = PACKED RECORD
  319.     samplePtr: Ptr;                             { if nil then samples are in sample area }
  320.     numChannels: LONGINT;                       { number of channels,  ie mono = 1 }
  321.     sampleRate: Fixed;                          { sample rate in Apples Fixed point representation }
  322.     loopStart: LONGINT;                         { same meaning as regular SoundHeader }
  323.     loopEnd: LONGINT;                           { same meaning as regular SoundHeader }
  324.     encode: Byte;                               { data structure used , stdSH, extSH, or cmpSH }
  325.     baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  326.     numFrames: LONGINT;                         { length in total number of frames }
  327.     AIFFSampleRate: Extended80;                   { IEEE sample rate }
  328.     markerChunk: Ptr;                           { sync track }
  329.     instrumentChunks: Ptr;                      { AIFF instrument chunks }
  330.     AESRecording: Ptr;
  331.     sampleSize: INTEGER;                        { number of bits in sample }
  332.     futureUse1: INTEGER;                        { reserved by Apple }
  333.     futureUse2: LONGINT;                        { reserved by Apple }
  334.     futureUse3: LONGINT;                        { reserved by Apple }
  335.     futureUse4: LONGINT;                        { reserved by Apple }
  336.     sampleArea: PACKED ARRAY [0..0] OF Byte;    { space for when samples follow directly }
  337.     END;
  338.  
  339. ConversionBlockPtr = ^ConversionBlock;
  340. ConversionBlock = RECORD
  341.     destination: INTEGER;
  342.     unused: INTEGER;
  343.     inputPtr: CmpSoundHeaderPtr;
  344.     outputPtr: CmpSoundHeaderPtr;
  345.     END;
  346.  
  347. SMStatusPtr = ^SMStatus;
  348. SMStatus = PACKED RECORD
  349.     smMaxCPULoad: INTEGER;
  350.     smNumChannels: INTEGER;
  351.     smCurCPULoad: INTEGER;
  352.     END;
  353.  
  354. SCStatusPtr = ^SCStatus;
  355. SCStatus = RECORD
  356.     scStartTime: Fixed;
  357.     scEndTime: Fixed;
  358.     scCurrentTime: Fixed;
  359.     scChannelBusy: BOOLEAN;
  360.     scChannelDisposed: BOOLEAN;
  361.     scChannelPaused: BOOLEAN;
  362.     scUnused: BOOLEAN;
  363.     scChannelAttributes: LONGINT;
  364.     scCPULoad: LONGINT;
  365.     END;
  366.  
  367. AudioSelectionPtr = ^AudioSelection;
  368. AudioSelection = PACKED RECORD
  369.     unitType: LONGINT;
  370.     selStart: Fixed;
  371.     selEnd: Fixed;
  372.     END;
  373.  
  374. SndDoubleBufferPtr = ^SndDoubleBuffer;
  375. SndDoubleBuffer = PACKED RECORD
  376.     dbNumFrames: LONGINT;
  377.     dbFlags: LONGINT;
  378.     dbUserInfo: ARRAY [0..1] OF LONGINT;
  379.     dbSoundData: PACKED ARRAY [0..0] OF Byte;
  380.     END;
  381.  
  382. SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
  383. SndDoubleBufferHeader = PACKED RECORD
  384.     dbhNumChannels: INTEGER;
  385.     dbhSampleSize: INTEGER;
  386.     dbhCompressionID: INTEGER;
  387.     dbhPacketSize: INTEGER;
  388.     dbhSampleRate: Fixed;
  389.     dbhBufferPtr: ARRAY [0..1] OF SndDoubleBufferPtr;
  390.     dbhDoubleBack: ProcPtr;
  391.     END;
  392.  
  393.  
  394. FUNCTION SndDoCommand(chan: SndChannelPtr;cmd: SndCommand;noWait: BOOLEAN): OSErr;
  395.     INLINE $A803;
  396. FUNCTION SndDoImmediate(chan: SndChannelPtr;cmd: SndCommand): OSErr;
  397.     INLINE $A804;
  398. FUNCTION SndNewChannel(VAR chan: SndChannelPtr;synth: INTEGER;init: LONGINT;
  399.     userRoutine: ProcPtr): OSErr;
  400.     INLINE $A807;
  401. FUNCTION SndDisposeChannel(chan: SndChannelPtr;quietNow: BOOLEAN): OSErr;
  402.     INLINE $A801;
  403. FUNCTION SndPlay(chan: SndChannelPtr;sndHdl: Handle;async: BOOLEAN): OSErr;
  404.     INLINE $A805;
  405. FUNCTION SndAddModifier(chan: SndChannelPtr;modifier: ProcPtr;id: INTEGER;
  406.     init: LONGINT): OSErr;
  407.     INLINE $A802;
  408. FUNCTION SndControl(id: INTEGER;VAR cmd: SndCommand): OSErr;
  409.     INLINE $A806;
  410.  
  411. PROCEDURE SetSoundVol(level: INTEGER);
  412. PROCEDURE GetSoundVol(VAR level: INTEGER);
  413. PROCEDURE StartSound(synthRec: Ptr;numBytes: LONGINT;completionRtn: ProcPtr);
  414. PROCEDURE StopSound;
  415. FUNCTION SoundDone: BOOLEAN;
  416.  
  417. FUNCTION SndSoundManagerVersion: NumVersion;
  418.     INLINE $203C,$000C,$0008,$A800;
  419. FUNCTION SndStartFilePlay(chan: SndChannelPtr;fRefNum: INTEGER;resNum: INTEGER;
  420.     bufferSize: LONGINT;theBuffer: Ptr;theSelection: AudioSelectionPtr;theCompletion: ProcPtr;
  421.     async: BOOLEAN): OSErr;
  422.     INLINE $203C,$0D00,$0008,$A800;
  423. FUNCTION SndPauseFilePlay(chan: SndChannelPtr): OSErr;
  424.     INLINE $203C,$0204,$0008,$A800;
  425. FUNCTION SndStopFilePlay(chan: SndChannelPtr;async: BOOLEAN): OSErr;
  426.     INLINE $203C,$0308,$0008,$A800;
  427. FUNCTION SndChannelStatus(chan: SndChannelPtr;theLength: INTEGER;theStatus: SCStatusPtr): OSErr;
  428.     INLINE $203C,$0010,$0008,$A800;
  429. FUNCTION SndManagerStatus(theLength: INTEGER;theStatus: SMStatusPtr): OSErr;
  430.     INLINE $203C,$0014,$0008,$A800;
  431. PROCEDURE SndGetSysBeepState(VAR sysBeepState: INTEGER);
  432.     INLINE $203C,$0018,$0008,$A800;
  433. FUNCTION SndSetSysBeepState(sysBeepState: INTEGER): OSErr;
  434.     INLINE $203C,$001C,$0008,$A800;
  435. FUNCTION SndPlayDoubleBuffer(chan: SndChannelPtr;theParams: SndDoubleBufferHeaderPtr): OSErr;
  436.     INLINE $203C,$0020,$0008,$A800;
  437.  
  438. FUNCTION MACEVersion: NumVersion;
  439.     INLINE $203C,$0000,$0010,$A800;
  440. PROCEDURE Comp3to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  441.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  442.     INLINE $203C,$0004,$0010,$A800;
  443. PROCEDURE Exp1to3(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  444.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  445.     INLINE $203C,$0008,$0010,$A800;
  446. PROCEDURE Comp6to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  447.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  448.     INLINE $203C,$000C,$0010,$A800;
  449. PROCEDURE Exp1to6(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  450.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  451.     INLINE $203C,$0010,$0010,$A800;
  452.  
  453.  
  454. {$ENDC}    { UsingSound }
  455.  
  456. {$IFC NOT UsingIncludes}
  457.     END.
  458. {$ENDC}
  459.  
  460.